import { ref, computed } from "vue";
import { defineStore } from "pinia";
import { member_details } from "@/api/travel.js";

// 用户信息存放到pinia中 防止页面跳转重复请求数据

export const useCounterStore = defineStore("counter", {
  // 相当于 vue 的 data
  state() {
    return {
      userData: {},
    };
  },
  // 相当于 vue 的 computed
  getters: {},
  // 相当于 vue 的 methods
  actions: {
    // 查看用户信息
    async getUserDetails(data) {
      const token = localStorage.getItem("token");
      if (!token) {
        this.userData = {};
        return {};
      };
      let res = await member_details();
      this.userData = res.data;
      // console.log('pinia',this.userData)
      return res;
    },

    // 退出登录
    removeUser() {
      localStorage.removeItem("token");
      this.userData = {};
      location.reload();
    },
  },
});
